import { vitePluginForArco } from '@arco-plugins/vite-vue';
import vue from '@vitejs/plugin-vue';
import { defineConfig, externalizeDepsPlugin } from 'electron-vite';
import { resolve } from 'node:path';
import AutoImport from 'unplugin-auto-import/vite';
import { ArcoResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';

export default defineConfig( {
  main: {
    plugins: [ externalizeDepsPlugin() ]
  },
  preload: {
    plugins: [ externalizeDepsPlugin() ]
  },
  renderer: {
    resolve: {
      alias: {
        '@renderer': resolve( 'src/renderer/src' ),
        '@preload': resolve( 'src/preload' )
      }
    },
    css: {
      preprocessorOptions: {
        scss: {
          api: 'modern-compiler' // 防止sass的legacy-js-api报错
        }
      }
    },
    plugins: [
      vue(),
      AutoImport( {
        resolvers: [ ArcoResolver() ],
        imports: [ 'vue' ],
        dts: true // 生成类型声明文件，默认为auto-imports.d.ts
      } ),
      vitePluginForArco( {
        style: 'css'
      } ),
      Components( {
        resolvers: [
          ArcoResolver( {
            sideEffect: true
          } )
        ]
      } )
    ]
  }
} );
